﻿using System.Windows.Input;
using Arch.Client.Commands;
using Arch.Samples.RiaServices.Infrastructure;
using Arch.Samples.Model;
using Arch.Samples.RiaServices.Services;

namespace Arch.Samples.RiaServices.ViewModels
{
    public class TodoSearchViewModel : CollectionViewModelBase<Todo>
    {
        public ICommand SearchCommand { get; protected set; }

        public string SearchQuery { get;  set; }

        public TodoSearchViewModel(TodoContext context) : base(context)
        {
            SearchCommand = new RelayCommand(Search);
        }

        public void Search()
        {
            Context.Load(Context.SearchTodosQuery(SearchQuery), 
                l => Items.Reload(l.Entities));
        }
    }
}
